package com.project.work.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.project.common.annotation.Log;
import com.project.common.core.controller.BaseController;
import com.project.common.core.domain.AjaxResult;
import com.project.common.enums.BusinessType;
import com.project.work.domain.BasicWorkOrder;
import com.project.work.service.IBasicWorkOrderService;
import com.project.common.utils.poi.ExcelUtil;
import com.project.common.core.page.TableDataInfo;

/**
 * 基础—工单Controller
 * 
 * @author ruoyi
 * @date 2025-01-05
 */
@RestController
@RequestMapping("/work/order")
public class BasicWorkOrderController extends BaseController
{
    @Autowired
    private IBasicWorkOrderService basicWorkOrderService;

    /**
     * 查询基础—工单列表
     */
    @PreAuthorize("@ss.hasPermi('work:order:list')")
    @GetMapping("/list")
    public TableDataInfo list(BasicWorkOrder basicWorkOrder)
    {
        startPage();
        List<BasicWorkOrder> list = basicWorkOrderService.selectBasicWorkOrderList(basicWorkOrder);
        return getDataTable(list);
    }

    /**
     * 导出基础—工单列表
     */
    @PreAuthorize("@ss.hasPermi('work:order:export')")
    @Log(title = "基础—工单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BasicWorkOrder basicWorkOrder)
    {
        List<BasicWorkOrder> list = basicWorkOrderService.selectBasicWorkOrderList(basicWorkOrder);
        ExcelUtil<BasicWorkOrder> util = new ExcelUtil<BasicWorkOrder>(BasicWorkOrder.class);
        util.exportExcel(response, list, "基础—工单数据");
    }

    /**
     * 获取基础—工单详细信息
     */
    @PreAuthorize("@ss.hasPermi('work:order:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(basicWorkOrderService.selectBasicWorkOrderById(id));
    }

    /**
     * 新增基础—工单
     */
    @PreAuthorize("@ss.hasPermi('work:order:add')")
    @Log(title = "基础—工单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BasicWorkOrder basicWorkOrder)
    {
        return toAjax(basicWorkOrderService.insertBasicWorkOrder(basicWorkOrder));
    }

    /**
     * 修改基础—工单
     */
    @PreAuthorize("@ss.hasPermi('work:order:edit')")
    @Log(title = "基础—工单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BasicWorkOrder basicWorkOrder)
    {
        return toAjax(basicWorkOrderService.updateBasicWorkOrder(basicWorkOrder));
    }

    /**
     * 删除基础—工单
     */
    @PreAuthorize("@ss.hasPermi('work:order:remove')")
    @Log(title = "基础—工单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(basicWorkOrderService.deleteBasicWorkOrderByIds(ids));
    }
}
